import { version } from '../../package.json';
import { Router } from 'express';
import facets from './facets';

export default ({ config, db }) => {
	let api = Router();

	// mount the facets resource
	api.use('/facets', facets({ config, db }));

	// perhaps expose some API metadata at the root
	api.get('/', (req, res) => {
		res.json({ version });
	});
	api.get('/testTimout',(req, res) => {
		const testTimout = setTimeout(()=>{
			clearTimeout(testTimout)
			res.json({ version });
		}, 5000)
	});

	api.get('/err', function (req, res) {
		//throw new Error('exception'); 
		setTimeout(function () {
			throw new Error('500 exception'); // 抛出一个异步异常
		}, 1000);
	})

	return api;
}
